class Api::V1::BeeFramesController < Api::V1::BaseController
  before_action :authenticate_request!

  def index
    @bee_frames = apply_scopes(BeeFrame).all
    @bee_frames = paginate(@bee_frames)
    render json: @bee_frames, meta: paginate_meta(@bee_frames)
  end

  def create
    begin
      @bee_frame = BeeFrame.new(create_params)
      authorize @bee_frame
      @bee_frame.save!
      render json: @bee_frame, status: 201
    rescue ActiveRecord::StatementInvalid
      @bee_frame.errors.add(:exec_error, 'Contact Administrator')
      error_render(@bee_frame, 403)
    rescue => err
      error_render(err.record, 403)
    end
  end

  def show
    @bee_frame = BeeFrame.find(params[:id])
    render json: @bee_frame, status: 200
  end

  def update
    begin
      @bee_frame = BeeFrame.find(params[:id])
      @bee_frame.update_attributes!(create_params)
      render json: @bee_frame, status: 200
    rescue => err
      error_render(err.record, 403)
    end
  end

  def destroy
    begin
      @bee_frame = BeeFrame.find(params[:id])
      @bee_frame.destroy!
      render status: 204
    rescue ActiveRecord::RecordNotFound
      render status: 404
    rescue => err
      error_render(err.record, 403)
    end
  end

  private

  def create_params
    params_parse(params)
  end

end
